package sprintServer.start;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import sprintServer.dbconnect.Conn;

public class MassgeUpdate {
	StringBuffer sql = new StringBuffer();
	Connection con ;
	PreparedStatement pstmt;
	
	@SuppressWarnings("finally")
	public int massgeUp(String id,String massge,String tgId,boolean check){
		String sendcheck;
		int result = 0;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy년 MM월 dd일 "+ "HH:mm:ss a");
		String time = sdf.format(new Date());
		if(check){
			sendcheck = "YES";
		}else{
			sendcheck = "NO";
		}
		
		sql.append("insert into message (");
		sql.append("   fromId");
		sql.append("  ,toId");
		sql.append("  ,massage");
		sql.append("  ,time");
		sql.append("  ,sendresult");
		sql.append(") values (");
		sql.append("  ?");
		sql.append(" ,?");
		sql.append(" ,?");
		sql.append(" ,?");
		sql.append(" ,?");
		sql.append(")");
		try{
			con = Conn.getConnection();
			pstmt = con.prepareStatement(sql.toString());
			pstmt.setString(1, id);
			pstmt.setString(2, tgId);
			pstmt.setString(3, massge);
			pstmt.setString(4, time);
			pstmt.setString(5, sendcheck);
			result = pstmt.executeUpdate();
			
		}catch(SQLException se){}
		finally{
			try{if(pstmt != null)pstmt.close();}catch	(SQLException se1){}
			try{if(con != null)con.close();}catch	(SQLException se1){}	
			return result;
		}

		
	}
}
